
// The main application class. This contains the core instances
// and also handles modus; like the chatbox modus and the logged out modus.
var Chatbox = new Class({
	
	// Create new instances of everything and save it.
	initialize: function(root)
	{
		var ajaxReq = new AjaxRequest(root);
		var dialogs = new Dialogs();
		var session = new Session();
		
		this.ajaxReq = ajaxReq;
		this.dialogs = dialogs;
		this.session = session;
		this.chat    = null; // this is specified when the user is logged in.
		
		// TODO: Remove
		this.hello = 'Hello!';
	},
	
	// TODO: Remove
	sayHello: function()
	{
		alert(this.hello);
		
	},
	
	// Get the chatbox modus class.
	getChat: function()  { return this.chat;  },
	setChat: function(c) { this.chat = c; },
	
	// Functions for retrieving instances.
	getClsAjaxReq: function() { return this.ajaxReq; },
	getClsDialog:  function() { return this.dialogs; },
	getClsSession: function() { return this.session; },
	
	// Start the chatbox
	start: function()
	{
		// Is there a session? (stupid question)
		// TODO: Clean up
		if (this.session.status == -1)
		{
			this.showLogin();
			
		} // end if
		
	}, // end function initialize
	
	// Show the login panel
	showLogin: function()
	{
		// Load the library..
		cimport('panels.Site.Login', function(atr)
		{
			// Create a new login dialog.
			atr.getClsDialog().create(new PanelLogin(atr));
			
		}, this);
		
		// Also pre load the register library.
		cimport('panels.Site.Register');
		
	}, // end function showLogin
	
	// Show the register panel
	showRegister: function()
	{
		// Load the register panel when that's not done yet..
		cimport('panels.Site.Register', function(atr)
		{
			// And show it!
			atr.getClsDialog().create(new PanelRegister(atr));
			
		}, this);
		
	}, // end function showRegister
	
	// Start the chatbox modus
	startChatbox: function(info)
	{
		// Procress info gotten from the login event.
		this.session.process(info);
		
		// The user needs to be logged in ofcourse.
		if (this.session.getStatus() < 0)
			return;
			
		// Import the main chatbox library
		cimport('chatbox.Main', function(atr)
		{
			// 
			if (atr.getChat() == null)
				atr.setChat(new ChatboxMain(atr));
			else
				atr.getChat().makeActive();
			
		}, this);
		
	} // end function startChatbox
	
}); // end class Chatbox

cimport_loaded('core.Chatbox');